package com.educate.ucenter.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.educate.common.web.R;
import com.educate.ucenter.model.bo.ChildBO;
import com.educate.ucenter.rpc.api.ChildService;
import lombok.extern.log4j.Log4j2;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Log4j2
@RestController
@RequestMapping("/child")
public class ChildController {

    @Reference(version = "${api.service.version}",
            application = "${dubbo.application.id}",
            url = "${dubbo.application.url}")
    private ChildService childService;

    /**
     * 创建小孩
     *
     * @param bo
     * @return
     */
    @PostMapping(value = "/create")
    public R<String> create(@RequestBody ChildBO bo) {
        ChildBO childBO = childService.create(bo);
        return R.ok(childBO.getChildId());
    }

    @PostMapping(value = "/delete")
    public R delete(@RequestBody ChildBO bo) {
        childService.delete(bo);
        return R.ok();
    }

    @PostMapping(value = "/delete/{childId}")
    public R delete(@PathVariable String childId) {
        childService.delete(childId);
        return R.ok();
    }

    @PostMapping(value = "/detail/{childId}")
    public R<ChildBO> detail(@PathVariable String childId) {
        ChildBO bo = childService.detail(childId);
        return R.ok(bo);
    }

    @PostMapping(value = "/detail")
    public R<ChildBO> detail(@RequestBody ChildBO bo) {
        ChildBO detail = childService.detail(bo);
        return R.ok(detail);
    }

    @PostMapping(value = "/update")
    public R<ChildBO> update(@RequestBody ChildBO bo) {
        childService.update(bo);
        return R.ok();
    }

    @PostMapping(value = "/query")
    public R<Page<ChildBO>> query(@RequestBody ChildBO bo) {
        Page<ChildBO> result = childService.query(bo);
        return R.ok(result);
    }

    @PostMapping(value = "/listByFamily")
    public R<List<ChildBO>> listByFamily(@RequestBody ChildBO bo) {
        List<ChildBO> result = childService.listByFamily(bo);
        return R.ok(result);
    }


}
